<%--
  Created by IntelliJ IDEA.
  User: lw
  Date: 2021/6/28
  Time: 13:36
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <title>Title</title>
    <link rel="stylesheet" href="<c:url value="/static/css/font.css"/>">
    <link rel="stylesheet" href="<c:url value="/static/css/xadmin.css"/>">
    <script type="text/javascript" src="<c:url value="/static/lib/layui/layui.js"/>" charset="utf-8"></script>
    <script type="text/javascript" src="<c:url value="/static/js/xadmin.js"/>"></script>
</head>
<body>
<div class="layui-fluid">
    <div class="layui-row">
        <form class="layui-form" id="updateform">
            <div class="layui-form-item">
                <label for="uname" class="layui-form-label">
                    <span class="x-red">*</span>单元名称
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="uname" name="uname" class="layui-input" value="${unit.getUnName()}">
                </div>
            </div>

            <div class="layui-form-item">
                <label for="fno" class="layui-form-label">
                    <span class="x-red">*</span>隶属楼栋
                </label>
                <div class="layui-input-inline">
                    <select name="fno" id="fno">
                        <option value="">请选择楼栋</option>
                        <c:forEach items="${floors}" var="model">
                            <c:if test="${unit.getfNo() != model.getfNo()}">
                                <option value="${model.getfNo()}">${model.getfName()}</option>
                            </c:if>
                            <c:if test="${unit.getfNo() == model.getfNo()}">
                                <option value="${model.getfNo()}" selected>${model.getfName()}</option>
                            </c:if>
                        </c:forEach>
                    </select>
                </div>
            </div>

            <input type="hidden" name="unno" value="${unit.getUnNo()}">

            <div class="layui-form-item">
                <button class="layui-btn" lay-filter="update" lay-submit="">修改</button>
            </div>
        </form>
    </div>
</div>

<script>

    layui.use(['form', 'layer', 'jquery'],
        function () {
            $ = layui.jquery;
            var form = layui.form,
                layer = layui.layer;

            // //自定义验证规则
            // form.verify({
            //     nikename: function (value) {
            //         if (value.length < 5) {
            //             return '昵称至少得5个字符啊';
            //         }
            //     },
            //     pass: [/(.+){6,12}$/, '密码必须6到12位'],
            //     repass: function (value) {
            //         if ($('#L_pass').val() != $('#L_repass').val()) {
            //             return '两次密码不一致';
            //         }
            //     }
            // });

            //监听提交
            form.on('submit(update)',
                function (data) {
                    console.log(data);
                    // alert("aaaaaaaa")
                    //发异步，数据提交
                    $.post({
                        url:"<c:url value="/unitUpdateServlet"/>",
                        data:$('#updateform').serialize(),
                        success: function(result){
                            // alert("POST请求到的数据：" + result);
                            if (result === "true"){
                                layer.alert("修改成功", {
                                        icon: 6
                                    },
                                    function () {
                                        //关闭当前frame
                                        xadmin.close();

                                        // 可以对父窗口进行刷新
                                        xadmin.father_reload();
                                    });
                            }else {
                                layer.alert("修改失败", {
                                        icon: 6
                                    },
                                    function () {
                                        //关闭当前frame
                                        xadmin.close();

                                        // 可以对父窗口进行刷新
                                        xadmin.father_reload();
                                    });
                            }
                        },
                        error:function (err) {
                            alert("错误"+err)
                        }
                    })
                    return false;
                });
        });
</script>
</body>
</html>
